<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ include file="/WEB-INF/jsp/commons/includes.jsp"%>

<c:if test="${not empty page}">
    <div class="page">
        <div>

            <c:if test="${page.hasPre}">
                <a class="prev" href="javascript:;">&lt;&lt;</a>
            </c:if>

            <%--<span class="current">1</span>--%>
            <%--<a class="num" href="javascript:;">2</a>--%>
            <%--<a class="num" href="javascript:;">3</a>--%>

            <c:forEach var="i" begin="1" end="${page.rollPage}">
                <c:choose>
                    <c:when test="${page.pageNo - nowCoolPage <= 0}">
                        <c:set var="p" value="${i}"/>
                    </c:when>
                    <c:when test="${page.pageNo + nowCoolPage - 1 >= page.totalPages}">
                        <c:set var="p" value="${page.totalPages - page.rollPage + i}"/>
                    </c:when>
                    <c:otherwise>
                        <c:set var="p" value="${page.pageNo - page.nowCoolPageCeil + i}"/>
                    </c:otherwise>
                </c:choose>

                <c:choose>
                    <c:when test="${p > 0 && p != page.pageNo}">
                        <c:if test="${p <= page.totalPages}">
                            <a class="num" href="javascript:;">${p}</a>
                        </c:if>
                    </c:when>
                    <c:otherwise>
                        <c:if test="${p > 0 && page.totalPages != 1}">
                            <span class="current">${p}</span>
                        </c:if>
                    </c:otherwise>
                </c:choose>
            </c:forEach>

            <c:if test="${page.hasNext}">
                <a class="next" href="javascript:;">&gt;&gt;</a>
            </c:if>

            <span class="rows">共${page.totalCount}条记录，${page.totalPages}页</span>
        </div>
    </div>

    <script type="text/javascript">
        $(function() {

            $(".prev").click(function(){
                var pNo = $("#searchForm input[name='pageNo']").val();
                $("#searchForm input[name='pageNo']").val(parseInt(pNo) - 1);
                $("#searchForm").submit();
            });
            $(".next").click(function(){
                var pNo = $("#searchForm input[name='pageNo']").val();
                $("#searchForm input[name='pageNo']").val(parseInt(pNo) + 1);
                $("#searchForm").submit();
            });
            $(".num").click(function(){
                $("#searchForm input[name='pageNo']").val($(this).text());
                $("#searchForm").submit();
            });
        });
    </script>
</c:if>